package com.easy.service.impl;

import com.easy.bean.User;
import com.easy.mapper.UserDao;
import com.easy.service.UserService;
import com.easy.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserDao userDao;
    //新增数据
    @Override
    public User add(User user) {
        userDao.add(user);
        //通过主键查询数据库中的数据
        User result=userDao.one(user.getId());
        return result;
    }

    @Override
    public int del(Integer id) {
        return userDao.del(id);
    }

    @Override
    public User edit(User user) {
        userDao.edit(user);
        User result=userDao.one(user.getId());
        return result;
    }

    @Override
    public List<User> all(User user) {
        return userDao.all(user);
    }

    @Override
    public User one(Integer id) {
        return userDao.one(id);
    }

    @Override
    public void page(Page page, User user) {
        int count = userDao.pageCount(user);
        Object data=userDao.page(page, user);
        page.setCount(count);
        page.setData(data);
    }
}